package upload;

import javax.servlet.http.HttpServletRequest;

/**
 * 
 * @author CSDN
 *
 */
public class UploadListener implements OutputStreamListener {
	
    private HttpServletRequest request;
    private int fileSize = 0;
    private int writtenSize = 0;

    public UploadListener(HttpServletRequest request) {
        this.request = request;
        fileSize = request.getContentLength();
    }

    public void start() {
        updateUploadInfo("start");
    }

    public void write(int b) {
    	writtenSize = writtenSize + b;
        updateUploadInfo("progress");
    }

    public void end() {
        updateUploadInfo("end");
    }

    private void updateUploadInfo(String status) {
        request.getSession().setAttribute("uploadInfo", new UploadInfo(fileSize, writtenSize, status));
    }

}
